package com.xq.shop.controller;


import com.xq.shop.dto.EditServiceDescriptionDto;
import com.xq.shop.dto.EditUserDto;
import com.xq.shop.service.IServiceDescriptionService;
import com.xq.shop.service.IUserService;
import com.xq.shop.vo.ServiceDescriptionVo;
import com.xq.shop.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import utils.BaseResult;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 服务说明表 前端控制器
 * </p>
 *
 * @author gaoxiaojin
 * @since 2024-07-19
 */
@RestController
@RequestMapping("/service/description")
public class ServiceDescriptionController {

    private final IServiceDescriptionService serviceDescriptionService;
    private final IUserService userService;

    @Autowired
    public ServiceDescriptionController(IServiceDescriptionService serviceDescriptionService, IUserService userService) {
        this.serviceDescriptionService = serviceDescriptionService;
        this.userService = userService;
    }

    @RequestMapping("/query")
    public BaseResult<List<ServiceDescriptionVo>> query(HttpServletRequest request) {
        userService.getInfo(request);
        BaseResult<List<ServiceDescriptionVo>> result = new BaseResult<>();
        List<ServiceDescriptionVo> voList = serviceDescriptionService.queryServiceDescription();
        result.initializeSuccess(voList);
        return result;
    }

    @RequestMapping("/edit")
    public BaseResult<Void> edit(@RequestBody @Validated EditServiceDescriptionDto dto, HttpServletRequest request) {
        UserVo vo = userService.getInfo(request);
        BaseResult<Void> result = new BaseResult<>();
        serviceDescriptionService.editServiceDescription(dto, vo.getId());
        result.initializeSuccess();
        return result;
    }

}
